package main

import (
	"backSever/routers"
	"time"

	"github.com/gin-contrib/cors"
	"github.com/gin-gonic/gin"
)

func main() {
	r := gin.Default()
	// r.LoadHTMLGlob("templates/*")
	r.Static("/static", "./static")

	// 配置：CORS 中间件
	r.Use(cors.New(cors.Config{
		AllowOrigins:     []string{"http://localhost:3000"},                                       // 指定允许的前端地址
		AllowMethods:     []string{"GET", "POST", "PUT", "DELETE", "OPTIONS"},                     //允许的 HTTP 方法
		AllowHeaders:     []string{"Origin", "Content-Type", "Authorization", "x-requested-with"}, // 添加 Authorization
		ExposeHeaders:    []string{"Content-Length"},
		AllowCredentials: true,           // 允许携带 Cookie
		MaxAge:           12 * time.Hour, // 预检请求缓存时间
	}))

	// CORS 不拦截设置
	// r.Use(cors.Default())

	routers.DefaultRoutersInit(r)
	routers.GeekRoutersInit(r)
	r.Run(":80")
}
